package top.jiangqiang.qianyi.common.properties;

import jakarta.annotation.PostConstruct;
import lombok.Data;
import org.dromara.hutool.core.io.file.FileUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import top.jiangqiang.qianyi.common.constants.GlobalConstants;

@Configuration
@ConfigurationProperties(prefix = GlobalConstants.GLOBAL_PREFIX + ".cache")
@Data
public class CacheProperties {
    /**
     * 全局缓存路径
     */
    @Value("#{systemProperties['os.name'].toString().toLowerCase().startsWith('windows') ?'D:/cachePath':'./cachePath'}")
    private String cachePath;

    @PostConstruct
    public void initDir() {
        if (!FileUtil.exists(cachePath)) {
            FileUtil.mkdir(cachePath);
        }
    }
}
